unit player;


interface
uses main, engine, types, sysutils,  windows, ukapsule, upomocnicza,
Controls, Forms, DateUtils, loader, utils, defaults, settings, display, dialogs;
type
  tkliperstate = (
    STATE_STOP,
    STATE_PLAY,
    STATE_PAUSE,
    STATE_UNKNOWN
    );



type TKPlayer = class

  public
    engine: TMPengine;
    state: tkliperstate;
    frm: tklipermainform;
 
    timeend: cardinal;
    timestart: cardinal;
    mode: integer;
  public
    constructor Create(f: tklipermainform);
  procedure play;
  procedure stop;
  procedure pause;
  function getPlayingTime: longint;
  destructor destroyer;
  procedure playDVD;
  private



end;

var kplayer: TKPlayer;

implementation

{ TKPlayer }
destructor TKPlayer.destroyer;
begin
  engine.destroy;
  inherited destroy;

end;

constructor TKPlayer.Create(f: tklipermainform);
begin
    self.frm:=f;
    self.engine := Tmpengine.Create(
    mainform.screenpanel,
    sets,
    frm.onPlay,
    frm.onStop,
    frm.onError,
    frm.onInfo,
    frm.onLoaded,
    frm.screenpanel.Color
    );
end;



function TKPlayer.getPlayingTime: longint;
begin
  if timeend = 0 then result := 0 else
    result := secondsBetween(timestart, timeend);
end;


procedure TKPlayer.pause;
begin
  engine.pause;
end;

procedure TKPlayer.play;
begin
    if engine.isstoped then engine.reopen else engine.play;
end;

procedure TKPlayer.playDVD;
  var
  drive: string;
  loader1: tloader;
begin
  with frm do begin
  drive := '';
  loader1:=tloader.create(frm);

  loader1.start(translatestr('KTS_INFO_MAINFORM_OPENING_DVD'));
  playbutton.Enabled := false;
  mode := MODE_DVD;
  if not settingsform.dvdautodetectcheck.checked then
    drive := settingsform.drivecombo.Text
  else begin
   //autodetect here !
  end;
  engine.opendvd(drive, -1, -1, -1);
  engine.play;
  end;
end;

procedure TKPlayer.stop;
begin
   engine.stop;
end;
end.


